<template>
	<view>
		<u-navbar title="设置" backIconColor="#fff" titleColor="#fff" :background="background"></u-navbar>
		<view class="">
			<u-cell-group>
				<u-cell-item title="格言" @click="showModal = true">{{geyan.motto}}</u-cell-item>
				<u-cell-item title="密码修改" @click="xiugai = true"></u-cell-item>
				<u-cell-item title="退出登录" @click="tuichu()"></u-cell-item>
			</u-cell-group>
		</view>
		<!-- modal -->
		<u-modal v-model="showModal" :show-title="false" @confirm="confirm1()" @cancel="cancel1()" :showCancelButton="true">
			<view class="u-p-30">
				<u-input placeholder="请输入内容..." maxlength="32" v-model="geyan.motto"></u-input>
			</view>
		</u-modal>
		<u-modal v-model="xiugai" :show-title="false" @confirm="confirm()" @cancel="cancel()" :showCancelButton="true">
			<view class="u-p-30">
				<u-input placeholder="请输入原来的密码..." maxlength="32" v-model="user3.userInfo.pwd"></u-input>
				<u-input placeholder="请输入新的密码..." maxlength="32" v-model="user3.newPwd"></u-input>
			</view>
		</u-modal>
		<!-- picker -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfoData:{
					headImg:""
				},
				background: {
					'background-image': 'linear-gradient(45deg, #2BC3C8, #84E7B9)'
				},
				list: [{
					text: '男',
					value:1
				}, {
					text: '女',
					value:2
				}],
				geyan:{
					motto:"",
					stuNumber:""
				},
				user3:{
					userInfo:{
						pwd:"",
						stuNumber:"",
					},
					manager:{
						pwd:"",
						name:""
					},
					newPwd:""
				},
				showModal:false,
				xiugai:false,
				mama:false,
				yici:true
			}
		},
		onLoad() {
			 
			 const value=uni.getStorageSync('scr1')
			 this.userInfoData.headImg=value
			 console.log("上传头像")
			 
		},
		onShow(){
			this.mama=true
		},
		methods: {
			tuichu(){
				uni.setStorageSync("wen","")
				uni.setStorageSync("user1","");
				uni.setStorageSync("admin","");
				this.$u.toast("已经退出登录")
				setTimeout(function(){
					uni.navigateTo({
						url:"/pages/login/login"
					})
				},1000);
			},
			confirm1(){
				const va1=uni.getStorageSync('shu01')
				const value1=uni.getStorageSync('wen')
				if(value1==""||va1=="12"){
					this.$u.toast('请先登录用户再更改格言！')
					return
				}else if(value1=="1"){
					const value=uni.getStorageSync('user1')
					this.geyan.stuNumber=value.stuNumber
					console.log(this.geyan.stuNumber)
					uni.request({
					 	url:"http://192.168.137.139:8080/changeMotto",
						method:"POST",
						data:this.geyan,
						success: (res) => {
						 if (res.data.code*1==200) {
							 try{
								uni.setStorageSync('geyan',res.data.result)
								console.log("页面跳转")
								this.$u.toast('格言已修改...,请重新登录会显示新格言');
								console.log(res)
								// uni.navigateBack()
							 }catch(e){
								 this.$u.toast('身份信息格式异常')
								console.log(res)
							 }
						 } else{
							this.$u.toast('用户名或者密码错误')
							console.log(res)
						 }
						}
					})
				}else if(value1=="2"){
					const value=uni.getStorageSync('admin')
					this.geyan.name=value.name
					console.log(this.geyan.name)
					uni.request({
					 	url:"http://192.168.137.139:8080/adminChangMotto",
						method:"POST",
						data:this.geyan,
						success: (res) => {
						 if (res.data.code*1==200) {
							 try{
								uni.setStorageSync('geyan',res.data.result)
								console.log("页面跳转")
								this.$u.toast('格言已修改...,请重新登录会显示新格言');
								console.log("管理员格言修改成功")
								console.log(res)
								// uni.navigateBack()
							 }catch(e){
								 this.$u.toast('身份信息格式异常')
								console.log(res)
							 }
						 } else{
							this.$u.toast('用户名或者密码错误')
							console.log(res)
						 }
						}
					})
				}
				
			},
			cancel1(){
				this.showModal = false
			},
			onShow(){
				const value1=uni.getStorageSync("wen")
				if(value1=="1"){
					const value=uni.getStorageSync('user1')
					this.geyan.motto=value.motto	
				}else if(value1=="2"){
					const value=uni.getStorageSync('admin')
					this.geyan.motto=value.motto
					}
			},
			confirm(){
				const va1=uni.getStorageSync('shu01')
				const value1=uni.getStorageSync('wen')
				if(value1==""||va1=="12"){
					this.$u.toast('请先登录用户再更改密码！')
					return
				}else if(value1=="1"){
					const value=uni.getStorageSync('user1')
					this.user3.userInfo.stuNumber=value.stuNumber
					if(this.user3.userInfo.pwd==""){
						this.$u.toast('请输入密码！')
						return
					}
					if(this.user3.userInfo.pwd!=value.pwd){
						this.$u.toast('旧密码输入错误，请重新输入！')
						this.user3.userInfo.pwd=""
						return
					}
					if(this.user3.newPwd==""){
						this.$u.toast('请输入新密码')
						return
					}
					if(this.user3.userInfo.pwd==value.pwd){
						console.log("正在修改密码")
						uni.request({
						 	url:"http://192.168.137.139:8080/changePwd",
							method:"POST",
							data:this.user3,
							success: (res) => {
							 if (res.data.code*1==200) {
								 try{
									uni.setStorageSync('user3',res.data.result)
									console.log("修改密码")
									this.$u.toast('密码已修改...');
									console.log(res)
									// uni.navigateBack()
								 }catch(e){
									 this.$u.toast('身份信息格式异常')
									console.log(res)
								 }
							 } else{
								this.$u.toast('用户名或者密码错误')
								console.log(res)
							 }
							}
						})
					}
					}
				else if(value1=="2"){
						const value=uni.getStorageSync('admin')
						this.user3.manager.name=value.name
						if(this.user3.userInfo.pwd==""){
							this.$u.toast('请输入密码！')
							console.log("shurumma")
							return
						}
						if(this.user3.userInfo.pwd!=value.pwd){
							this.$u.toast('旧密码输入错误，请重新输入！')
							this.user3.userInfo.pwd=""
							return
						}
						if(this.user3.newPwd==""){
							this.$u.toast('请输入新密码')
							return
						}
						if(this.user3.userInfo.pwd==value.pwd){
							this.user3.manager.pwd=value.pwd
							console.log("正在修改密码")
							uni.request({
							 	url:"http://192.168.137.139:8080/adminChangePwd",
								method:"POST",
								data:this.user3,
								success: (res) => {
								 if (res.data.code*1==200) {
									 try{
										uni.setStorageSync('user3',res.data.result)
										console.log("修改密码")
										this.$u.toast('管理员密码已修改...');
										console.log(res)
										// uni.navigateBack()
									 }catch(e){
										 this.$u.toast('身份信息格式异常')
										console.log(res)
									 }
								 } else{
									this.$u.toast('用户名或者密码错误')
									console.log(res)
								 }
								}
							})
				}
				
				}
			},
			cancel(){
				this.xiugai = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #ededed;
	}
</style>
